#include <iostream>
#include <stdio.h>

/*
 * 构造函数与析构函数		P151
 */

class Base
{
	public:
		Base (void);
		void demo(void);
		~Base(void);
};

Base::Base()
{
	printf("Constructor.\n");
}

Base::~Base()
{
	printf("Destructor.\n");
}

void Base::demo(void)
{
	printf("Base.\n");
}


int main()
{
	Base *p = new Base;
    
    printf("%d\n", sizeof(class Base));    // 1
	p->demo();
	delete p;
}

/*
	Constructor.
	Base.
	Destructor.
 */

 #if 0
/*
 * intel
 */
00000000000011ea <_ZN4BaseC1Ev>:
    11ea:	f3 0f 1e fa          	endbr64 
    11ee:	55                   	push   %rbp
    11ef:	48 89 e5             	mov    %rsp,%rbp	// rbp=rsp
    11f2:	48 83 ec 10          	sub    $0x10,%rsp	// rsp-=0x10
    11f6:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)	// rbp-0x8=rdi
    11fa:	48 8d 3d 04 0e 00 00 	lea    0xe04(%rip),%rdi        # 2005 <_ZStL19piecewise_construct+0x1>
    1201:	e8 da fe ff ff       	callq  10e0 <puts@plt>	// puts(rdi)
    1206:	90                   	nop
    1207:	c9                   	leaveq 
    1208:	c3                   	retq   
    1209:	90                   	nop

000000000000120a <_ZN4BaseD1Ev>:
    120a:	f3 0f 1e fa          	endbr64 
    120e:	55                   	push   %rbp
    120f:	48 89 e5             	mov    %rsp,%rbp
    1212:	48 83 ec 10          	sub    $0x10,%rsp
    1216:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    121a:	48 8d 3d f1 0d 00 00 	lea    0xdf1(%rip),%rdi        # 2012 <_ZStL19piecewise_construct+0xe>
    1221:	e8 ba fe ff ff       	callq  10e0 <puts@plt>	// puts(rdi)
    1226:	90                   	nop
    1227:	c9                   	leaveq 
    1228:	c3                   	retq   
    1229:	90                   	nop

000000000000122a <_ZN4Base4demoEv>:
    122a:	f3 0f 1e fa          	endbr64 
    122e:	55                   	push   %rbp
    122f:	48 89 e5             	mov    %rsp,%rbp
    1232:	48 83 ec 10          	sub    $0x10,%rsp
    1236:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    123a:	48 8d 3d dd 0d 00 00 	lea    0xddd(%rip),%rdi        # 201e <_ZStL19piecewise_construct+0x1a>
    1241:	e8 9a fe ff ff       	callq  10e0 <puts@plt>	// puts(rdi)
    1246:	90                   	nop
    1247:	c9                   	leaveq 
    1248:	c3                   	retq   

0000000000001249 <main>:
    1249:	f3 0f 1e fa          	endbr64 
    124d:	55                   	push   %rbp
    124e:	48 89 e5             	mov    %rsp,%rbp	// rbp=rsp
    1251:	41 54                	push   %r12		// rsp-=8; (rsp)=r12
    1253:	53                   	push   %rbx		// rsp-=8; (rsp)=rbx
    1254:	48 83 ec 10          	sub    $0x10,%rsp	// rsp-=0x10
    1258:	bf 01 00 00 00       	mov    $0x1,%edi	// edi=1		sizeof(class Base) = 1
    125d:	e8 4e fe ff ff       	callq  10b0 <_Znwm@plt>	// new(1)
    1262:	48 89 c3             	mov    %rax,%rbx	// rbx=rax=return value
    1265:	48 89 df             	mov    %rbx,%rdi	// rdi=rbx
    1268:	e8 7d ff ff ff       	callq  11ea <_ZN4BaseC1Ev>	// Base(rdi)
    126d:	48 89 5d e8          	mov    %rbx,-0x18(%rbp)	// rbp-0x18=rbx
    1271:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=rbp-0x18
    1275:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    1278:	e8 ad ff ff ff       	callq  122a <_ZN4Base4demoEv>	// demo(rdi)
    127d:	48 8b 5d e8          	mov    -0x18(%rbp),%rbx	// rbx=rbp-0x18
    1281:	48 85 db             	test   %rbx,%rbx	// rbx&rbx			????
    1284:	74 15                	je     129b <main+0x52>	// 相等跳转
    1286:	48 89 df             	mov    %rbx,%rdi	// rdi=rbx
    1289:	e8 7c ff ff ff       	callq  120a <_ZN4BaseD1Ev>	// ~base(rdi)
    128e:	be 01 00 00 00       	mov    $0x1,%esi		// esi=0x1	sizeof(class Base) = 1
    1293:	48 89 df             	mov    %rbx,%rdi		// rdi=rbx
    1296:	e8 25 fe ff ff       	callq  10c0 <_ZdlPvm@plt>	// delete(rbx)
    129b:	b8 00 00 00 00       	mov    $0x0,%eax	// eax=0
    12a0:	eb 1f                	jmp    12c1 <main+0x78>
    12a2:	f3 0f 1e fa          	endbr64 
    12a6:	49 89 c4             	mov    %rax,%r12	// r12=rax
    12a9:	be 01 00 00 00       	mov    $0x1,%esi	// esi=0x1	sizeof(class Base) = 1
    12ae:	48 89 df             	mov    %rbx,%rdi	// rdi=rbx
    12b1:	e8 0a fe ff ff       	callq  10c0 <_ZdlPvm@plt>	// delete(rdi)
    12b6:	4c 89 e0             	mov    %r12,%rax	// rax=r12
    12b9:	48 89 c7             	mov    %rax,%rdi	// rdi=rax
    12bc:	e8 2f fe ff ff       	callq  10f0 <_Unwind_Resume@plt>	// unwind_resume(rdi)
    12c1:	48 83 c4 10          	add    $0x10,%rsp	// rsp+=0x10
    12c5:	5b                   	pop    %rbx
    12c6:	41 5c                	pop    %r12
    12c8:	5d                   	pop    %rbp
    12c9:	c3                   	retq   

/*
 * arm
 */
000000000040091c <_ZN4BaseC1Ev>:
  40091c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400920:	910003fd 	mov	x29, sp
  400924:	f9000fa0 	str	x0, [x29, #24]
  400928:	90000000 	adrp	x0, 400000 <_init-0x730>
  40092c:	912ce000 	add	x0, x0, #0xb38
  400930:	97ffffac 	bl	4007e0 <puts@plt>	// puts(x0)
  400934:	d503201f 	nop
  400938:	a8c27bfd 	ldp	x29, x30, [sp], #32
  40093c:	d65f03c0 	ret

0000000000400940 <_ZN4BaseD1Ev>:
  400940:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400944:	910003fd 	mov	x29, sp
  400948:	f9000fa0 	str	x0, [x29, #24]
  40094c:	90000000 	adrp	x0, 400000 <_init-0x730>
  400950:	912d2000 	add	x0, x0, #0xb48
  400954:	97ffffa3 	bl	4007e0 <puts@plt>	// puts(x0)
  400958:	d503201f 	nop
  40095c:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400960:	d65f03c0 	ret

0000000000400964 <_ZN4Base4demoEv>:
  400964:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400968:	910003fd 	mov	x29, sp
  40096c:	f9000fa0 	str	x0, [x29, #24]
  400970:	90000000 	adrp	x0, 400000 <_init-0x730>
  400974:	912d6000 	add	x0, x0, #0xb58
  400978:	97ffff9a 	bl	4007e0 <puts@plt>
  40097c:	d503201f 	nop
  400980:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400984:	d65f03c0 	ret

0000000000400988 <main>:
  400988:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  40098c:	910003fd 	mov	x29, sp
  400990:	a90153f3 	stp	x19, x20, [sp, #16]
  400994:	d2800020 	mov	x0, #0x1                   	// #1
  400998:	97ffff9a 	bl	400800 <_Znwm@plt>	// new(1)
  40099c:	aa0003f3 	mov	x19, x0
  4009a0:	aa1303e0 	mov	x0, x19
  4009a4:	97ffffde 	bl	40091c <_ZN4BaseC1Ev>	// Base(x0)
  4009a8:	f90017b3 	str	x19, [x29, #40]
  4009ac:	f94017a0 	ldr	x0, [x29, #40]
  4009b0:	97ffffed 	bl	400964 <_ZN4Base4demoEv>	// base->demo(x0)
  4009b4:	f94017b3 	ldr	x19, [x29, #40]		// x19=x29+40
  4009b8:	f100027f 	cmp	x19, #0x0		// x19-0x0
  4009bc:	540000c0 	b.eq	4009d4 <main+0x4c>  // b.none
  4009c0:	aa1303e0 	mov	x0, x19			// x0=x19
  4009c4:	97ffffdf 	bl	400940 <_ZN4BaseD1Ev>	// ~base(x0)
  4009c8:	d2800021 	mov	x1, #0x1                   	// #1
  4009cc:	aa1303e0 	mov	x0, x19			// x0=x19
  4009d0:	97ffff70 	bl	400790 <_ZdlPvm@plt>	// delete(x0)
  4009d4:	52800000 	mov	w0, #0x0                   	// #0
  4009d8:	14000007 	b	4009f4 <main+0x6c>
  4009dc:	aa0003f4 	mov	x20, x0
  4009e0:	d2800021 	mov	x1, #0x1                   	// #1
  4009e4:	aa1303e0 	mov	x0, x19			// x0=x19
  4009e8:	97ffff6a 	bl	400790 <_ZdlPvm@plt>	// delete(x0)
  4009ec:	aa1403e0 	mov	x0, x20
  4009f0:	97ffff88 	bl	400810 <_Unwind_Resume@plt>
  4009f4:	a94153f3 	ldp	x19, x20, [sp, #16]
  4009f8:	a8c37bfd 	ldp	x29, x30, [sp], #48
  4009fc:	d65f03c0 	ret


 #endif
